% Remember to use the lgrind style

\Head{}
\File{findIntervals.txt}{2007}{10}{29}{12:53}{2569}
\index{findIntervals}\Proc{findIntervals}\L{\LB{\K{private}_\K{static}_\V{HashSet}\<\K{int}[\,]\>_\V{findIntervals}(\K{int}[\,]_\V{ySequence},_\K{int}_\V{indexFirstY},_\K{int}_\V{mult},_\K{int}_\V{y})\{}}
\L{\LB{}\Tab{4}{\K{int}_\V{indexOfFirstY}_=_\V{indexFirstY};_\C{}//_stores_the_index_of_the_first_y\CE{}}}
\L{\LB{}\Tab{4}{\K{int}_\V{indexOfSecondY}=_\N{0};_\C{}//_records_the_next_y_that_we_are_trying_to_reach\CE{}}}
\L{\LB{}\Tab{4}{\K{int}_\V{multiplicity}_=_\V{mult};}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\K{int}_\V{status}_=_\N{0};_\C{}//used_to_let_the_algorithm_to_perform_different_tasks_in_the_execution\CE{}}}
\L{\LB{}\Tab{4}{\K{boolean}_\V{seeEachOther}_=_\K{true};_\C{}//used_to_understand_if_there_is_any_number_n\<y_between_the_two_y\CE{}}}
\L{\LB{}\Tab{4}{\K{boolean}_\V{coveredAtLeastTwoYi}_=_\K{false};}}
\L{\LB{}\Tab{4}{\K{int}[\,]_\V{interval}_=_\K{new}_\K{int}[\N{2}];_\C{}//stores_the_interval_that_we_have_found\CE{}}}
\L{\LB{}\Tab{4}{\K{int}_\V{tmpIndex}_=_\-\N{1};_\C{}//temp_variable_used_for_mixed_purposes\CE{}}}
\L{\LB{}\Tab{4}{\V{HashSet}\<\K{int}[\,]\>_\V{intervalsSet}_=_\K{new}_\V{HashSet}\<\K{int}[\,]\>();_\C{}//here_we_store_the_set_of_intervals\CE{}}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\K{while}(\K{true})\{}}
\L{\LB{}\Tab{8}{\K{switch}(\V{status})\{}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{8}{\K{case}_\N{0}\V{:}}}
\L{\LB{}\Tab{12}{\V{coveredAtLeastTwoYi}_=_\K{false};}}
\L{\LB{}\Tab{12}{\V{seeEachOther}_=_\K{true};}}
\L{\LB{}\Tab{12}{\C{}//try_to_extend_the_interval_to_the_left\CE{}}}
\L{\LB{}\Tab{12}{\V{tmpIndex}_=_\V{indexOfFirstY};}}
\L{\LB{}\Tab{12}{\K{while}(_(\V{tmpIndex}_\>_\N{0})_\&\&_(\V{ySequence}[\V{tmpIndex}\-\N{1}]_\>=_\V{y})_)_}}
\L{\LB{}\Tab{16}{\V{tmpIndex}\-\-;}}
\L{\LB{}\Tab{12}{\C{}//update_our_interval\CE{}}}
\L{\LB{}\Tab{12}{\V{interval}[\N{0}]_=_\V{tmpIndex};}}
\L{\LB{}\Tab{12}{\V{interval}[\N{1}]_=_\V{indexOfFirstY};}}
\L{\LB{}\Tab{12}{\C{}//no_break_since_when_we_start_from_case_0_the_subsequent_step_will_always_be_case_1_;)\CE{}}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{8}{\K{case}_\N{1}\V{:}}}
\L{\LB{}\Tab{12}{\V{multiplicity}\-\-;_\C{}//we_are_proceeding_towards_the_next_y._\3register\3_this_event\CE{}}}
\L{\LB{}\Tab{12}{}}
\L{\LB{}\Tab{12}{\C{}//find_the_next_occurrence_of_y_and_see_also_if_the_interval_can_be_created\CE{}}}
\L{\LB{}\Tab{12}{\V{tmpIndex}_=_\V{indexOfFirstY};\C{}//records_until_which_index_we_arrive,_in_case_!seeEachOther\CE{}}}
\L{\LB{}\Tab{12}{\V{indexOfSecondY}=\V{indexOfFirstY}+\N{1};_\C{}//records_the_index_of_the_next_occurrence_of_Y\CE{}}}
\L{\LB{}\Tab{12}{\K{for}(;_\V{indexOfSecondY}\<\V{ySequence}.\V{length};_\V{indexOfSecondY}++)\{}}
\L{\LB{}\Tab{16}{\K{if}(\V{ySequence}[\V{indexOfSecondY}]_==_\V{y})}}
\L{\LB{}\Tab{20}{\K{break};}}
\L{\LB{}\Tab{16}{\K{if}(\V{ySequence}[\V{indexOfSecondY}]_\>_\V{y}_\&\&_\V{seeEachOther})}}
\L{\LB{}\Tab{20}{\V{tmpIndex}++;}}
\L{\LB{}\Tab{16}{\K{else}}}
\L{\LB{}\Tab{20}{\V{seeEachOther}_=_\K{false};}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}}
\L{\LB{}\Tab{12}{\K{if}(\V{seeEachOther})\{_\C{}//we_can_make_the_interval_between_indexOfFirstY_and_indexOfSecondY\CE{}}}
\L{\LB{}\Tab{16}{\K{if}(\V{multiplicity}_==_\N{0})\{\C{}//_if_this_was_the_last_y.\,.\,.\CE{}}}
\L{\LB{}\Tab{20}{\V{tmpIndex}_=_\V{indexOfSecondY};\C{}//.\,.\,._first_let{'}s_see_if_we_can_go_to_the_right_some_more\CE{}}}
\L{\LB{}\Tab{20}{\K{while}(_(\V{tmpIndex}_\<_\V{ySequence}.\V{length}\-\N{1})_\&\&_(\V{ySequence}[\V{tmpIndex}+\N{1}]_\>=_\V{y})_)}}
\L{\LB{}\Tab{24}{\V{tmpIndex}++;}}
\L{\LB{}}
\L{\LB{}\Tab{20}{\V{interval}[\N{1}]_=_\V{tmpIndex};}}
\L{\LB{}\Tab{20}{\V{intervalsSet}.\V{add}(\V{interval});}}
\L{\LB{}\Tab{20}{\K{return}_\V{intervalsSet};}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{16}{\K{else}\{}}
\L{\LB{}\Tab{24}{\V{coveredAtLeastTwoYi}_=_\K{true};}}
\L{\LB{}\Tab{24}{\V{status}_=_\N{1};}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{\K{else}\{_\C{}//_they_don{'}t_\3see\3_each_other\CE{}}}
\L{\LB{}\Tab{16}{\K{if}(!\V{coveredAtLeastTwoYi})\{}}
\L{\LB{}\Tab{20}{\K{if}(\V{multiplicity}_==_\N{0})_\C{}//only_one_yi_remaining\CE{}}}
\L{\LB{}\Tab{24}{\K{return}_\V{intervalsSet};}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{16}{\K{else}\{}}
\L{\LB{}\Tab{20}{\V{interval}[\N{1}]_=_\V{tmpIndex};}}
\L{\LB{}\Tab{20}{\V{intervalsSet}.\V{add}(\V{interval});}}
\L{\LB{}\Tab{20}{\K{if}(\V{multiplicity}_==_\N{0})}}
\L{\LB{}\Tab{24}{\K{return}_\V{intervalsSet};}}
\L{\LB{}\Tab{16}{\}}}
\L{\LB{}\Tab{16}{\V{status}_=_\N{0};}}
\L{\LB{}\Tab{12}{\}}}
\L{\LB{}\Tab{12}{\V{indexOfFirstY}_=_\V{indexOfSecondY};}}
\L{\LB{}\Tab{12}{\K{break};}}
\L{\LB{}\Tab{8}{\}}}
\L{\LB{}\Tab{4}{\}}}
\L{\LB{\}}}
